<?php
/**
 * 《考试管理》实用类
 *
 * @author 孙晓晔
 * @version $Id: InfoUtil.class.php 636 2009-11-25 05:49:36Z sunxy $
 */

require_once(dirname(__FILE__) . '/../AdminUtil.class.php');

class ExamUtil extends AdminUtil {
	public $type = array(
		'-' => '请选择',
		'1' => '单选题',
		'2' => '多选题',
		'3' => '判断题',
	
		'4' => '填空题',		
		'5' => '简答题',
		'9' => '其它',
	);
		
	function __construct() {
		$request['update'] = '$Date: 2009/03/03 07:24:42 $';
		$request['revision'] = '$Revision: 1.5 $';
			
		parent::__construct($request);
	}

	/**
	 *
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function delete($controller, $request) {
		$this->pretreat($controller);

		$db = newdb($this->dsn_w);
		$insql = "in ('000000000";
		while (list($k, $v) = each($request)) {
			if (substr($k, 0, 2) == "c_") {
				$insql .= "', '" . $v;
			}
		}
		$insql .= "')";
		$sql = "delete from " . $this->tbl . " WHERE id " . $insql;
		// debug($sql);
		$query = $db->query($sql);
		
		$controller->assign('baseLink', $this->doGet($request, 'findPost'));

		$this->findPost($controller, $request);
		return true;
	}

	/**
	 * 更新状态
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function status($controller, $request) {
		$this->pretreat($controller);

		$id = $request['id'];
		clean($this->tbl . "_id_" . $id);

		$status = $request['status'];

		$db = newdb($this->dsn_w);
		$fmt = "UPDATE %s SET status = '%s', modifytime = now() WHERE id = '%s'";
		$sql = sprintf($fmt, $this->tbl, $status, $id);
		// debug($sql);
		$db->query($sql);
		
		$controller->assign('baseLink', $this->doGet($request, 'findPost'));

		$this->findPost($controller, $request);
		return true;
	}
	
	function ajax_exchange($controller, $request) {
		$code = $request['currency'];
		$data = $this->_exchange($code);
		echo $data;
	}
	
	function admin($controller, $request) {
		$CategoryTree = array(
			'class'	  => 'Opened',		
				
			'个人简历' => array('cc'=>'exam.php?do=Exam.emp', 'js'=>''),
			'我的试卷' => array('cc'=>'exam.php?do=ExamEmp.my', 'js'=>''),
			// '公共笔试' => array('cc'=>'exam.php?do=Exam.pub', 'js'=>''),	
			// '专业笔试' => array('cc'=>'exam.php?do=Exam.professional', 'js'=>''),
			'退出' => 'index.php?do=Admin.logout',
		);
		
		$MenuTree = $this->tree($_SESSION['name'], $CategoryTree);
		$controller->assign('MenuTree', $MenuTree);

		// print_r($_SESSION['mytree']);

		$controller->display($request, 'admin');
		return true;
	}
	
	function tree_my($v) {
		return true;
	}
	
	function exam_t($id) {
		if (empty($id)) {
			return '';
		}

		return Common::name_id(Constant::tbl_exam, $id);
	}
	
	function question_t($id) {
		if (empty($id)) {
			return '';
		}

		return Common::name_id(Constant::tbl_question, $id);
	}
	
	function _ab($s) {
		if ($s == '') {
			return '';
		}
		
		$a = array("0", "1", "2", "3", "4", "5", "6");
		$b = array("A", "B", "C", "D", "E", "F", "G");
		
		$ret = '';
		for ($i = 0, $len = strlen($s); $i < $len; $i++) {
			$c = substr($s, $i, 1);
			$ret .= $b[$c];
		}
		
		return $ret;
	}
	
	function _cd($s) {
		if ($s == '') {
			return '';
		}
		
		
		$b = array("1"=>"（一）", "2"=>"（二）", "3"=>"（三）", "4"=>"（四）", "5"=>"（五）", "6"=>"（六）", "7"=>"（七）");
		
		return $b[$s];
	}
}